package cn.lin.util;


import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.lin.vo.HeaderVO;

import java.util.Date;
import java.util.List;

/**
 * @Author: Mr.s huang
 * @Date: 2024/12/3
 * 计算周数
 */
public class WeekUtil {

    /**
     * 计算总周期 和 进行到了第几周周期
     * @return
     */
    public List<HeaderVO> countTotalWeek(List<HeaderVO> list) {

        for (HeaderVO headerVO : list) {

            String beginDate = DateUtil.formatDate(headerVO.getBeginDate());

            String newDate = DateUtil.formatDate(new Date());

            String endDate = DateUtil.formatDate(headerVO.getEndDate());

            Date date1 = DateUtil.parse(beginDate);

            Date date2 = DateUtil.parse(endDate);

            Date date3 = DateUtil.parse(newDate);

            // 计算总周期
            long totalWeek = DateUtil.between(date1, date2, DateUnit.WEEK);

            // 进行到了第几周周期
            long currentWeek = DateUtil.between(date1, date3, DateUnit.WEEK);

            headerVO.setTotalWeek(totalWeek);

            headerVO.setCurrentWeek(currentWeek);
        }

        return list;
    }

}
